#include <stdio.h>
#include <stdlib.h>
#define InitSize 100

typedef struct
{
    int *data;
    int MaxSize, length;
} SqList;

bool InitList(SqList &L)
{
    L.data = (int *)malloc(InitSize * sizeof(int));
    for (int i = 0; i < InitSize; i++)
        L.data[i] = 0;
    L.length = 0;
    L.MaxSize = InitSize;

    return true;
}

bool InsertList(SqList &L, int i, int e)
{
    if (L.length == L.MaxSize)
        return false;
    if (i < 1 || i > L.length + 1)
        return false;
    for (int j = L.length - 1; j >= i - 1; j--)
        L.data[j + 1] = L.data[j];

    L.data[i - 1] = e;
    L.length++;

    return true;
}

int LocateElem(SqList L, int e)
{
    if (L.length == 0)
        return 0;
    for (int i = 0; i < L.length; i++)
        if (L.data[i] == e)
            return i;

    return 0;
}
bool DeleteList(SqList &L, int e)
{
    int index = LocateElem(L, e);
    for (int i = index; i < L.length; i++)
        L.data[i] = L.data[i + 1];

    L.length--;

    return true;
}

void PList(SqList L)
{
    for (int i = 0; i < L.length; i++)
        printf("data[%d]=%d\n", i, L.data[i]);
}

int main()
{
    SqList L;
    InitList(L);
    InsertList(L, 1, 6);
    InsertList(L, 2, 1);
    InsertList(L, 3, 4);
    InsertList(L, 4, 2);
    InsertList(L, 5, 3);
    printf("here is the sequencelist:\n");
    PList(L);
    DeleteList(L, 4);
    printf("here is the  deleted sequencelist:\n");
    PList(L);
    
    return 0;
}